{extend name="tplLayui/baseLayui" /}
{block name="headTitle"}{$page.pageTitle}{/block}
{block name="head"}
<script type="text/javascript"></script>
<style type="text/css">
body{ background-color: #F1F2F7 }
.layui-form-item .layui-inline {
    margin-bottom: 5px;
    margin-right: 0px;
}
.layui-card-body{
    padding: 15px;
    margin: 0px;
}
.layui-table{
    padding: 0px;
    margin: 0px !important;
}
.layui-table tbody tr:hover{
  background-color:white;
}
</style>
{/block}
{block name="content"}
<div class="layui-fluid layui-bg-gray">
    <div class="layui-row layui-bg-gray layui-col-space10">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">服务器[{$info.name ?? ''}]-任务配置<button style="float: right;margin-top: 6px;" class="layui-btn layui-btn-sm" onclick="layui.main.savePermission()">保存配置</button></div>
                <div class="layui-card-body">
                    <form class="layui-form" id="frm_permission">
                    <table class="layui-table" lay-size="sm">
                        <colgroup>
                            <col width="100">
                            <col width="150">
                            <col width="80">
                            <col>
                            <col width="100">
                            <col width="150">
                            <col width="150">
                            <col width="80">
                            <col width="80">
                        </colgroup>
                        <tbody>
                            <tr>
                                <td>项目</td>
                                <td>任务</td>
                                <td>命令类型</td>
                                <td>命令参数</td>
                                <td>监控数量</td>
                                <td>日志文件名</td>
                                <td>频率规则</td>
                                <td>任务状态</td>
                                <td>部署状态</td>
                            </tr>
                            {foreach $serverTasks as $k=>$v } 
                            {foreach $v['tasks'] as $k1=>$v1 } 
                                <tr>
                                    {if $k1==0}<td rowspan="{:count($v['tasks'])}">{$v.name}</td>{/if}
                                    <td>{$v1.name}</td>
                                    <td>{$v1.command_type_name}</td>
                                    <td>{$v1.command}</td>
                                    <td>{$v1.monitor_num}</td>
                                    <td>{$v1.log_file}</td>
                                    <td>{$v1.time_rule}</td>
                                    <td>{$v1.status_name}</td>
                                    <td><input class="task_ids" data-root="{$v.id}" type="checkbox" name="task_ids" lay-skin="switch" lay-text="开启|关闭" value="{$v1.id}" {if $v1['is_on_server'] == 1} checked {/if}></td>
                                </tr>
                                {/foreach}
                            {/foreach}
                        </tbody>
                    </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="tpljs"}
<script>
    var id = '{$info.id ?? 0}';
    layui.extend({
        index:'lib/index'
    }).use(['jquery','layer','form','index'], function() {
        var $=layui.jquery,
        admin = layui.admin,
        view = layui.view,
        layer=layui.layer,
        form=layui.form,
        m = {};
        m = {
            init: function () {
                form.render();
            }
            , savePermission: function () {
                var o = {}, task_ids = new Array();
                $('input[name="task_ids"]:checked').each(function () {
                    task_ids.push($(this).val());
                });
                o.id = id;
                o.task_ids = task_ids.join(',');
                $.post({
                    url:'saveServerTask',
                    data:o,
                    success:function(res){
                        if(res.code == 1){
                            layer.msg(res.msg);
                        }else{
                            layer.msg(res.msg);
                            // window.location.reload();
                        }
                    }
                })
            },
        };
        m.init();
        layui.main = m;
    });
</script>
{/block}


